using System;
using System.Collections.Generic;
using System.Text;
using MacomberMap.Common.Database_Interface;

namespace MacomberMap.Common.Data
{
    /// <summary>
    /// This interface provides a link to data points    
    /// </summary>
    public interface MM_Data_Point
    {
       

    }

    /// <summary>
    /// This class holds a data point that can be retrieved from CIM or any other data connector
    /// </summary>
    /// <typeparam name="T">The type of data the data point holds</typeparam>
    public class MM_Data_Point<T>
    {
        #region Variable declarations
        
        /// <summary>The value for the item</summary>
        private T _value;

        /// <summary>The data value to which this point belongs</summary>
        public MM_Data_Value DataValue;

        /// <summary>The database from which the information is retrieved</summary>
        public MM_Database SourceDatabase;

        /// <summary>The time stamp for the data point's last refresh</summary>
        public DateTime DataTime;

        /// <summary>
        /// The delegate for handling data value changes (strongly typed)
        /// </summary>
        /// <param name="DataPoint">The data point that has changed</param>
        /// <param name="NewValue">The new value of the data point</param>
        public delegate void ValueChangedDelegate(MM_Data_Point<T> DataPoint, T NewValue);
        
        /// <summary>The event to indicate a change of value</summary>
        public event ValueChangedDelegate ValueChanged;
                           
        /// <summary>
        /// The current value of the data point
        /// </summary>
        public T Value
        {
            get { return _value; }
            set
            {
                if (!_value.Equals(value))
                {
                    _value = value;
                    if (ValueChanged != null)
                        ValueChanged(this, value);
                }
            }
        }        
        #endregion

        #region Initialization
        /// <summary>
        /// Initialize a new MM data point
        /// </summary>
        /// <param name="DataValue">The data value for the point</param>
        /// <param name="InitialValue">The initial value for hte point</param>
        public MM_Data_Point(MM_Data_Value DataValue, T InitialValue)
        {
            this.DataValue = DataValue;
            this._value = InitialValue;

        }
        #endregion
    }
}
